import { ref } from 'vue'
import axios from '../plugins/axios'

export default (articleId: number) => {
   const support = async () => {
      await axios.request({ url: 'support', data: { articleId }, method: 'post' })
   }

   const supportInfo = ref<SupportModel>()
   const findOne = async () => {
      const res = await axios.request<SupportModel>({ url: `support/findOne/${articleId}` })
      supportInfo.value = res.data
   }

   const countNum = async () => {
      const res = await axios.request<{ num: number }>({ url: `support/count/${articleId}` })
      return res.data.num
   }

   const cancelSupport = async (id: number) => {
      await axios.request({ url: `support/${id}`, method: 'Delete' })
   }

   return { support, cancelSupport, findOne, countNum, supportInfo }
}
